package sy.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import sy.pageModel.BaseEntity;
import sy.pageModel.DataGrid;
import sy.pageModel.Json;
import sy.pageModel.Shop;
import sy.service.ShopServiceI;
import sy.util.StringUtil;

import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2016-07-06.
 */
@Controller
@RequestMapping("shopController")
public class ShopController extends BaseController{

    @Autowired
    private ShopServiceI shopService;

    @Autowired
    private HttpSession session;
    @RequestMapping("/datagrid.action")
    @ResponseBody
    public DataGrid findPicAction(Shop s){
        return shopService.findShopDataGird(s);
    }

    @RequestMapping("/add_currency.action")
    @ResponseBody
    public Json addPicAction(Shop s){
        int rows=0;
        Map map= StringUtil.findMap(s.getPic());
        s.setPic((String) map.get("pic"));
        s.setId((String) map.get("id"));
        try {
            rows=shopService.addShopService(s);
            if (rows>0)  logUserAction(session,"shopController/add_currency.action",s.toString());
        } catch (Exception e) {
            e.printStackTrace();
            rows=0;
        }
        Json js= StringUtil.findJson(rows,"添加");
        return js;
    }
    @RequestMapping("/edit_currency.action")
    @ResponseBody
    public Json editPicAction(Shop s){
        int rows=0;
        s.setPic(StringUtil.findStr(s.getPic()));
        try {
            rows=shopService.editShopService(s);
            if (rows>0)  logUserAction(session,"shopController/edit_currency.action",s.toString());
        } catch (Exception e) {
            e.printStackTrace();
            rows=0;
        }
        Json js= StringUtil.findJson(rows,"修改");
        return js;
    }


    @RequestMapping("/remove_currency.action")
    @ResponseBody
    public Json removePicAction(Shop s){
        int rows=0;
        try {
            rows= shopService.deleteShopService(s.getIds());
            if (rows>0)  logUserAction(session,"shopController/remove_currency.action",s.toString());
        } catch (Exception e) {
            e.printStackTrace();
            rows=0;
        }
        Json js= StringUtil.findJson(rows,"删除");
        return js;
    }
    @RequestMapping("/find_type.action")
    @ResponseBody
    public List<BaseEntity> findTypeList(){
        return shopService.findTypeList("商品系列");
    }
}
